const file = require("../service/file");
const ApiResult = require("../common/ApiResult");

module.exports = {
  /**
   * 文件上传
   * @param ctx
   * @return {Promise<void>}
   */
  upload: async function(ctx) {
    const files = ctx.request.files;
    try {
      const url = await file.uploadFile(files.file);
      ctx.body = ApiResult.SUCCESS({ url });
    } catch (e) {
      ctx.body = ApiResult.ERROR(e.message);
    }
  }
};
